package bom.example.common.service;

import bom.example.common.utils.SpringContextUtils;
import com.github.benmanes.caffeine.cache.Cache;
import org.springframework.stereotype.Component;

/**
 * @author X.I.O
 * @title: CacheService
 * @projectName springboot
 * @description: TODO
 * @date 2021/10/29 17:24
 */
@Component
public class CacheService {

    public Cache<String,Object> getCache(){
        Cache<String,Object> cache=(Cache)SpringContextUtils.getBean("cache");
        return cache;
    }

    public Object getCache(String key){
        Cache<String,Object> cache=getCache();
        Object value=cache.getIfPresent(key);
        return value;
    }

    public void putCache(String key,Object value){
        Cache<String,Object> cache=getCache();
        cache.put(key,value);
    }

}
